#ifndef DUMMY_H_
#define DUMMY_H_

#include <math.h>
#include <stdlib.h>
#include <iostream>
#include <stdio.h>

#include "CSurface.h"
#include "Character.h"
#include "Behavior/Align.h"
#include "Behavior/Nothing.h"
#include "Behavior/Face.h"
#include "Behavior/Wander.h"
#include "Behavior/VelocityMatch.h"
#include "Behavior/Seek.h"
#include "Behavior/Arrive.h"

using namespace std;

class Dummy : public Character { 
  public:
    SDL_Surface* carita;
    
    /*
     * Inicializa al bicho
     */
    bool OnInit(Character* target){
      if((surface = CSurface::OnLoad("images/dummy.png",true)) == NULL){
        cout << "Algo salio mal" << endl;
        return false;
      }
      
      if((carita = CSurface::OnLoad("images/dummy_head.png",true)) == NULL){
        cout << "Algo salio mal" << endl;
        return false;
      }
      
      /* Posicionamos el personaje */
      k = new Kinematic();
      k->position[0] = 200;
      k->position[1] = 220;
//    k->orientation = ((float) random() - random())/RAND_MAX * 2 * M_PI;
//    k->orientation = -2*M_PI;
      k->orientation = 0;;
      k->max_velocity = 0.15;
      k->max_rotation = 0.01;
      this->width = this->height = 20;
      
      /* Establecemos su comportamiento, y los vamos almacenando en el orden
       * de prioridad deseado
       */
      // Hay que meter TODOS los comportamientos del personaje en esta lista
      setBehavior* stB;
      stB->addBehavior(new Arrive(),this,target);
      behaviors.push_back(stB);
      return true;
    }

    /*
     * Pinta al bicho
     */
    void OnRender(SDL_Surface* display){
      CSurface::OnDraw(display, this->surface,
          this->k->position[0],
          this->k->position[1]);

      CSurface::OnDraw(display, this->carita,
          15*sin(k->orientation) +k->position[0]+ width/2+2,
          15*cos(k->orientation) +k->position[1]+ height/2+2);

      // printf("pos x = %f , pos y = %f \n",k->position[0]+ (this->width/2),k->position[0]+ (this->height/2));
    }

    /*
     * Aplica comportamiento, actualiza la posicion
     * y anima sprites (proximamente)
     */
    void OnLoop(long time){
      Steering* steering = this->getSteering();

      // DEBUG
//    cout << "S-Ang " << steering->angular << endl;
//    cout << "S-Lin " << steering->linear[0]<< "," << steering->linear[1] << endl;

      update(steering, time);
      delete steering;
    }
};

#endif
